From 84d568f5c9ceb342be7c883074ac8c5423ab1492 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Tue, 22 Sep 2009 08:26:16 +0100 Subject: [PATCH] Introduce new flavour of map_domain_page() Introduce a variant of map_domain_page() directly getting passed a struct page_info * argument, based on the observation that in many places the argument to this function so far simply was the result of page_to_mfn(). This is meaningful for the x86-64 case where map_domain_page() really just is an invocation of mfn_to_virt(), and hence the combined mfn_to_virt(page_to_mfn()) now represents a needless round trip conversion compressed -> uncompressed -> compressed of the MFN representation. Signed-off-by: Jan Beulich --- xen/arch/x86/hvm/stdvga.c | 6 +++--- xen/arch/x86/hvm/vlapic.c | 2 +- xen/arch/x86/mm.c | 2 +- xen/arch/x86/mm/hap/hap.c | 4 ++-- xen/arch/x86/mm/p2m.c | 2 +- xen/arch/x86/mm/paging.c | 6 ++---- xen/arch/x86/mm/shadow/common.c | 4 ++-- xen/arch/x86/tboot.c | 3 +-- xen/common/grant_table.c | 2 +- xen/common/page_alloc.c | 2 +- xen/common/tmem_xen.c | 2 +- xen/drivers/passthrough/amd/iommu_map.c | 2 +- xen/drivers/passthrough/amd/pci_amd_iommu.c | 2 +- xen/drivers/passthrough/vtd/iommu.c | 2 +- xen/include/asm-x86/hvm/svm/amd-iommu-proto.h | 2 +- xen/include/xen/domain_page.h | 5 +++++ 16 files changed, 25 insertions(+), 23 deletions(-) diff --git a/xen/arch/x86/hvm/stdvga.c b/xen/arch/x86/hvm/stdvga.c index 3e796a57bd..b2faaa0eca 100644 --- a/xen/arch/x86/hvm/stdvga.c +++ b/xen/arch/x86/hvm/stdvga.c @@ -85,14 +85,14 @@ const uint8_t gr_mask[9] = { static uint8_t *vram_getb(struct hvm_hw_stdvga *s, unsigned int a) { struct page_info *pg = s->vram_page[(a >> 12) & 0x3f]; - uint8_t *p = map_domain_page(page_to_mfn(pg)); + uint8_t *p = __map_domain_page(pg); return &p[a & 0xfff]; } static uint32_t *vram_getl(struct hvm_hw_stdvga *s, unsigned int a) { struct page_info *pg = s->vram_page[(a >> 10) & 0x3f]; - uint32_t *p = map_domain_page(page_to_mfn(pg)); + uint32_t *p = __map_domain_page(pg); return &p[a & 0x3ff]; } @@ -601,7 +601,7 @@ void stdvga_init(struct domain *d) if ( pg == NULL ) break; s->vram_page[i] = pg; - p = map_domain_page(page_to_mfn(pg)); + p = __map_domain_page(pg); clear_page(p); unmap_domain_page(p); } diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index 603a9200ab..bdd2473a18 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -978,7 +978,7 @@ int vlapic_init(struct vcpu *v) } if (vlapic->regs == NULL) { - vlapic->regs = map_domain_page_global(page_to_mfn(vlapic->regs_page)); + vlapic->regs = __map_domain_page_global(vlapic->regs_page); if ( vlapic->regs == NULL ) { dprintk(XENLOG_ERR, "map vlapic regs error: %d/%d\n", diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index d47250fa40..f11341a082 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -543,7 +543,7 @@ static int alloc_segdesc_page(struct page_info *page) struct desc_struct *descs; int i; - descs = map_domain_page(page_to_mfn(page)); + descs = __map_domain_page(page); for ( i = 0; i < 512; i++ ) if ( unlikely(!check_descriptor(page_get_owner(page), &descs[i])) ) diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c index 0e4ce30f68..74993ee0ad 100644 --- a/xen/arch/x86/mm/hap/hap.c +++ b/xen/arch/x86/mm/hap/hap.c @@ -255,7 +255,7 @@ static struct page_info *hap_alloc(struct domain *d) d->arch.paging.hap.free_pages--; - p = hap_map_domain_page(page_to_mfn(pg)); + p = __map_domain_page(pg); ASSERT(p != NULL); clear_page(p); hap_unmap_domain_page(p); @@ -293,7 +293,7 @@ static struct page_info *hap_alloc_p2m_page(struct domain *d) NULL, MEMF_bits(32) | MEMF_node(domain_to_node(d))); if ( likely(pg != NULL) ) { - void *p = hap_map_domain_page(page_to_mfn(pg)); + void *p = __map_domain_page(pg); clear_page(p); hap_unmap_domain_page(p); } diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 48132f3698..7fba54e0a2 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -200,7 +200,7 @@ p2m_next_level(struct domain *d, mfn_t *table_mfn, void **table, else flags &= ~_PAGE_PSE; /* Clear _PAGE_PSE (== _PAGE_PAT) */ - l1_entry = map_domain_page(mfn_x(page_to_mfn(pg))); + l1_entry = __map_domain_page(pg); for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) { new_entry = l1e_from_pfn(pfn + i, flags); diff --git a/xen/arch/x86/mm/paging.c b/xen/arch/x86/mm/paging.c index a0ff260729..051c5dc1f2 100644 --- a/xen/arch/x86/mm/paging.c +++ b/xen/arch/x86/mm/paging.c @@ -99,7 +99,6 @@ static mfn_t paging_new_log_dirty_page(struct domain *d, void **mapping_p) { - mfn_t mfn; struct page_info *page; page = alloc_domheap_page(NULL, MEMF_node(domain_to_node(d))); @@ -110,10 +109,9 @@ static mfn_t paging_new_log_dirty_page(struct domain *d, void **mapping_p) } d->arch.paging.log_dirty.allocs++; - mfn = page_to_mfn(page); - *mapping_p = map_domain_page(mfn_x(mfn)); + *mapping_p = __map_domain_page(page); - return mfn; + return page_to_mfn(page); } static mfn_t paging_new_log_dirty_leaf( diff --git a/xen/arch/x86/mm/shadow/common.c b/xen/arch/x86/mm/shadow/common.c index 42eed9fa49..6dfcb7698b 100644 --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -1578,7 +1578,7 @@ mfn_t shadow_alloc(struct domain *d, flush_tlb_mask(&mask); } /* Now safe to clear the page for reuse */ - p = sh_map_domain_page(page_to_mfn(sp+i)); + p = __map_domain_page(sp+i); ASSERT(p != NULL); clear_page(p); sh_unmap_domain_page(p); @@ -3130,7 +3130,7 @@ int shadow_enable(struct domain *d, u32 mode) } /* Fill it with 32-bit, non-PAE superpage entries, each mapping 4MB * of virtual address space onto the same physical address range */ - e = sh_map_domain_page(page_to_mfn(pg)); + e = __map_domain_page(pg); for ( i = 0; i < PAGE_SIZE / sizeof(*e); i++ ) e[i] = ((0x400000U * i) | _PAGE_PRESENT | _PAGE_RW | _PAGE_USER diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c index 49254273ec..e40605d118 100644 --- a/xen/arch/x86/tboot.c +++ b/xen/arch/x86/tboot.c @@ -205,8 +205,7 @@ static void tboot_gen_domain_integrity(const uint8_t key[TB_KEY_SIZE], page_list_for_each(page, &d->page_list) { - void *pg; - pg = map_domain_page(page_to_mfn(page)); + void *pg = __map_domain_page(page); vmac_update(pg, PAGE_SIZE, &ctx); unmap_domain_page(pg); } diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 771f79f28a..2adbd01420 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -1195,7 +1195,7 @@ gnttab_transfer( } sp = map_domain_page(mfn); - dp = map_domain_page(page_to_mfn(new_page)); + dp = __map_domain_page(new_page); memcpy(dp, sp, PAGE_SIZE); unmap_domain_page(dp); unmap_domain_page(sp); diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 395732dee5..44813ebf1c 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1235,7 +1235,7 @@ __initcall(pagealloc_keyhandler_init); void scrub_one_page(struct page_info *pg) { - void *p = map_domain_page(page_to_mfn(pg)); + void *p = __map_domain_page(pg); #ifndef NDEBUG /* Avoid callers relying on allocations returning zeroed pages. */ diff --git a/xen/common/tmem_xen.c b/xen/common/tmem_xen.c index c11aa60d6e..b7a308b019 100644 --- a/xen/common/tmem_xen.c +++ b/xen/common/tmem_xen.c @@ -268,7 +268,7 @@ static void *tmh_persistent_pool_page_get(unsigned long size) if ( (pi = _tmh_alloc_page_thispool(d)) == NULL ) return NULL; ASSERT(IS_VALID_PAGE(pi)); - return map_domain_page(page_to_mfn(pi)); + return __map_domain_page(pi); } static void tmh_persistent_pool_page_put(void *page_va) diff --git a/xen/drivers/passthrough/amd/iommu_map.c b/xen/drivers/passthrough/amd/iommu_map.c index 3d4e41548d..4d6bcc2acf 100644 --- a/xen/drivers/passthrough/amd/iommu_map.c +++ b/xen/drivers/passthrough/amd/iommu_map.c @@ -430,7 +430,7 @@ static u64 iommu_l2e_from_pfn(struct page_info *table, int level, (level - IOMMU_PAGING_MODE_LEVEL_1))); offset &= ~PTE_PER_TABLE_MASK; - table_vaddr = map_domain_page(page_to_mfn(table)); + table_vaddr = __map_domain_page(table); pde = table_vaddr + (offset * IOMMU_PAGE_TABLE_ENTRY_SIZE); next_table_maddr = amd_iommu_get_next_table_from_pte(pde); diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c index 1ce09305c7..a66a7f5200 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -335,7 +335,7 @@ static void deallocate_next_page_table(struct page_info* pg, int level) u64 next_table_maddr; int index; - table_vaddr = map_domain_page(page_to_mfn(pg)); + table_vaddr = __map_domain_page(pg); if ( level > 1 ) { diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index 145bf80ac3..9cbd17742c 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -154,7 +154,7 @@ u64 alloc_pgtable_maddr(struct acpi_drhd_unit *drhd, unsigned long npages) (node == -1 ) ? 0 : MEMF_node(node)); if ( !pg ) return 0; - vaddr = map_domain_page(page_to_mfn(pg)); + vaddr = __map_domain_page(pg); memset(vaddr, 0, PAGE_SIZE * npages); iommu_flush_cache_page(vaddr, npages); diff --git a/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h b/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h index cf559dcb22..b16e2e9b21 100644 --- a/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +++ b/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h @@ -131,7 +131,7 @@ static inline struct page_info* alloc_amd_iommu_pgtable(void) pg = alloc_domheap_page(NULL, 0); if ( pg == NULL ) return 0; - vaddr = map_domain_page(page_to_mfn(pg)); + vaddr = __map_domain_page(pg); memset(vaddr, 0, PAGE_SIZE); unmap_domain_page(vaddr); return pg; diff --git a/xen/include/xen/domain_page.h b/xen/include/xen/domain_page.h index 5240179cf0..95b939ff93 100644 --- a/xen/include/xen/domain_page.h +++ b/xen/include/xen/domain_page.h @@ -34,6 +34,9 @@ void unmap_domain_page(const void *va); void *map_domain_page_global(unsigned long mfn); void unmap_domain_page_global(const void *va); +#define __map_domain_page(pg) map_domain_page(__page_to_mfn(pg)) +#define __map_domain_page_global(pg) map_domain_page_global(__page_to_mfn(pg)) + #define DMCACHE_ENTRY_VALID 1U #define DMCACHE_ENTRY_HELD 2U @@ -97,9 +100,11 @@ domain_mmap_cache_destroy(struct domain_mmap_cache *cache) #else /* !CONFIG_DOMAIN_PAGE */ #define map_domain_page(mfn) mfn_to_virt(mfn) +#define __map_domain_page(pg) page_to_virt(pg) #define unmap_domain_page(va) ((void)(va)) #define map_domain_page_global(mfn) mfn_to_virt(mfn) +#define __map_domain_page_global(pg) page_to_virt(pg) #define unmap_domain_page_global(va) ((void)(va)) struct domain_mmap_cache { -- 2.30.2